<!--- ATTRIBUTE VALIDATION --->
<cfif NOT (isDefined("attributes.event") AND len(trim(attributes.event)))>
	<cfthrow detail="Event trigger failed: event name not specified.">
</cfif>
<!--- END ATTRIBUTE VALIDATION --->

<cfif structCount(attributes) GT 1>	<!--- if there's more than just the event name passed in --->
	<cfset theseValues = structNew()>
	<cfloop collection="#attributes#" item="I">
		<cfif I NEQ "event">
			<cfset evaluate("theseValues.#I# = attributes.#I#")>
		</cfif>
	</cfloop>
</cfif>

<cfif structKeyExists(application.eventRegistry, attributes.event)>	<!--- if this event has been registered --->
	<cfset I = 0>

	<cfloop array="#application.eventRegistry[attributes.event]#" index="thisEvent">	<!--- then loop through & invoke the listeners --->
		<cfif thisEvent.threaded>
			<cfset I++>

			<!--- IN THE FUTURE:
				need to checkup on running threads (via thread.status, checking for 'TERMINATED' namely Error, and 'WAITING' for hung threads)
				probably check existing threads on each request, or setup a rock-solid threaded thread watcher...
			 --->
			<cfthread action="run" name="#attributes.event#Handler#I#" priority="LOW">
				<cfinvoke component="#thisEvent.component#" method="#thisEvent.method#">	<!--- no return values --->
					<cfif isDefined("theseValues")>
						<cfinvokeargument name="values" value="#theseValues#">
					</cfif>
				</cfinvoke>
			</cfthread>
		<cfelse>
			<cfinvoke component="#thisEvent.component#" method="#thisEvent.method#">	<!--- no return values --->
				<cfif isDefined("theseValues")>
					<cfinvokeargument name="values" value="#theseValues#">
				</cfif>
			</cfinvoke>
		</cfif>
	</cfloop>
<cfelse>
	<!--- if the event is of the type "saveObject" or "loadObject" then assume it's an attempt to  --->
	<cfset objName = mid(attributes.event, 5, len(attributes.event))>

	<cfif fileExists("#application.path#/DAO/#objName#.cfc")>
		<cfset eventType = mid(attributes.event, 1, 4)>
		<cfif isDefined("attributes.#objName#")>
			<cfset thisObject = evaluate("attributes.objName")>
		<cfelse>
			<cfset thisObject = createObject("#objName#")>
			<cfloop collection="#attributes#" item="I">
				<cfif I NEQ "event">
					<cfset evaluate("thisObj.set#I#(attributes.#I#)")>
				</cfif>
			</cfloop>
		</cfif>

		<cfset evaluate("request.ORM = entity#eventType#(thisObject)")>
	</cfif>
</cfif>

<cfexit method="exittag">